
<template>
    <view class="shopping_cart flex a-item">
        <view class="cart_image">
            <image src="/static/image/cart_icon.png" alt="">
            <view class="redDot flex a-item j-center">{{ selectGoodsList.length  }}</view>
        </view>
        <view class="flex fl1">
            购物车  已添加&nbsp<span class="blue">{{ selectGoodsList.length  }}</span>&nbsp件
        </view>
        <view class="submit" @tap="submit">{{ type === 'stock' || type === 'capCart'? '确认' :'确认下单' }}</view>
    </view>
</template>

<script>
import {removeCacheShoppingCart, ShoppingCartList,cartType} from "@/models/shoppingCart";
// import {cartType} from "@/models/shoppingCart";
import pub from "@/common/pub";
export default {
    name: "shoppingCard",
    props:{
        type: {type:String,default:'cart'}
    },
    data(){
        return{
             selectGoodsList:[],
             cartType
        }
    },
    created() {
      console.log("===============",this.cartType[this.type])
        this.selectGoodsList = new ShoppingCartList(this.cartType[this.type]).toList()

        console.log("============",this.selectGoodsList)
    },
    methods:{
        submit(){
            //添加到单据界面并清理内存
          new ShoppingCartList(this.type).push(this.selectGoodsList)
            removeCacheShoppingCart(this.cartType[this.type])
            //更新
            pub.$emit('updateGoodsData')
            history.back()
            // uni.navigateBack()
        }
    }
}
</script>

<style scoped lang="scss">
.shopping_cart{
  background: white;
  height: 108rpx;
  padding-left: 46rpx;
  font-weight: 500;
  color: #666666;
  box-shadow: 0rpx -3rpx 20rpx 1rpx rgba(0,0,0,0.1);
  font-size: 28rpx;
  .cart_image{
    position: relative;
    width: 90rpx;
   
    .redDot{
      min-width: 28rpx;
      height: 28rpx;
      padding: 3rpx;
      border-radius: 28rpx;
      color: white;
      font-size: 24rpx;
      position: absolute;
      top: 0;
      right: 15rpx;
      background: red;
    }
    image{
      width: 64rpx;
      height: 64rpx;

    }
  }
  .submit{
    background: #016EF9;
    width: 200rpx;
    height: 76rpx;
    font-size: 32rpx;
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 40rpx;
  }
}
</style>
